<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
if($_RQ['op']=='get'){
	$_SESSION['merchfooternav']=$return['pluginset']['footernav'];
	$_SESSION['main_menus']=$return['pluginset']['footernav'];
	$_SESSION['forward_url']='jy_pifashop/member.index/';
	$_SESSION['indexurl']='jy_pifashop/index/';
	$item=pdo_get('jy_weishop_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('level','viptime'));
	$mylevel=pdo_get('jy_weishop_member_level',array('id'=>$item['level'],'uniacid'=>$_SESSION['uniacid']));
	$item['leveltitle']=$mylevel['title'];
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$credit_types=credit_types();
	$pay=uni_setting('pay');
	foreach($credit_types as $k=>$cv){
		if($k>2){
			$prizeType[]=array(
				'id'=>$k,
				'title'=>$cv,
				'api'=>$pay['credit'.$k.'_api'],
				'data'=>$return['member']['credit'.$k],
			);
		}
	}
	$item['credit_type']=$prizeType;
	$my_days = array(
			array('title'=>'我的优惠券','icon'=>'icon-youhuiquan','color'=>'#cc99ff','action'=>'jy_weishop/coupon.myindex/'),
			array('title'=>'微信会员卡','icon'=>'icon-daifahuo','color'=>'#cc99ff','action'=>'core/member.wxcard/main/'),
			array('title'=>'余额提现','icon'=>'icon-dixiaofei','color'=>'#cc99ff','action'=>'core/member.tixian/'),
			array('title'=>'地址管理','icon'=>'icon-position','color'=>'#cc99ff','action'=>'core/member.address/'),
			array('title'=>'帮助中心','icon'=>'icon-help','color'=>'#cc99ff','action'=>'jy_weishop/news.list/'),
			array('title'=>'获得购物卡','icon'=>'icon-qiangdan','color'=>'#cc99ff','action'=>'jy_weishop/member.getcard/'),
			array('title'=>'我的购物车','icon'=>'icon-gouwuche','color'=>'#cc99ff','action'=>'jy_weishop/member.cart/'),
			array('title'=>'我的购物卡','icon'=>'icon-pingzhengzhongxin','color'=>'#cc99ff','action'=>'jy_weishop/member.mycard/'),
			array('title'=>'我的关注','icon'=>'icon-woguanzhudepinpai','color'=>'#cc99ff','action'=>'jy_weishop/member.favorite/'),
			array('title'=>'我的足迹','icon'=>'icon-zuji','color'=>'#cc99ff','action'=>'jy_weishop/member.history/'),
	);
	$return['pluginset']['my_days'] = !empty($return['pluginset']['my_days']) ? $return['pluginset']['my_days'] : $my_days;
	$my_logs = array(
				array('title'=>'积分日志','icon'=>'icon-jifen','color'=>'#cc99ff','action'=>'core/member.credit_log/'),
				array('title'=>'余额日志','icon'=>'icon-jiangjiatongzhi','color'=>'#cc99ff','action'=>'core/member.credit_log/'),
				array('title'=>'提现日志','icon'=>'icon-trade','color'=>'#cc99ff','action'=>'core/member.cash_log/'),
				array('title'=>'红包日志','icon'=>'icon-ai-hongbao','color'=>'#cc99ff','action'=>'core/member.red_log/'),
	);
	$return['pluginset']['my_logs'] = !empty($return['pluginset']['my_logs']) ? $return['pluginset']['my_logs'] : $my_logs;
	$my_memberbtn = array(
				array('title'=>'领取优惠券','icon'=>'icon-youhuiquan1','color'=>'#cc99ff','action'=>'jy_weishop/coupon.index/'),
				array('title'=>'领取微信会员卡','icon'=>'icon-huiyuanqia','color'=>'#cc99ff','action'=>'core/member.wxcard/main'),
				array('title'=>'积分排行','icon'=>'icon-paixing','color'=>'#cc99ff','action'=>'jy_weishop/member.rank/'),
	);
	$return['pluginset']['my_memberbtn'] = !empty($return['pluginset']['my_memberbtn']) ? $return['pluginset']['my_memberbtn'] : $my_memberbtn;
	$return['item']=$item;
	$return['params']['type']=$_RQ['type']?:2;
	$return['feeurl']=$this->setting['feeurl']?:'jy_pifashop/index//ismerch=1';
	$status0 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'userdeleted'=>0,'status'=>0));
	$status1 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'userdeleted'=>0,'status'=>1));
	$status2 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'userdeleted'=>0,'status'=>2));
	$status3 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'userdeleted'=>0,'status'=>3,'iscomment'=>0));
	$cartnums= pdo_getsum('jy_weishop_member_cart',array('mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']),'total');
	$ratefee= pdo_getsum('jy_creditshop_log',array('mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid'],'paystatus'=>1),'ratefee');
	$ordertotal = pdo_count('jy_weishop_order',array('plugin_name'=>'jy_pifashop','uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ispay'=>1));
	$orderprice = pdo_getsum('jy_weishop_order',array('plugin_name'=>'jy_pifashop','uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ispay'=>1),'price');
	$return['statics']=array(
		'status0'=>$status0,
		'status1'=>$status1,
		'status2'=>$status2,
		'status3'=>$status3,
		'cartnums'=>$cartnums,
		'ratefee'=>$ratefee,
		'orderprice'=>$orderprice,
		'ordertotal'=>$ordertotal
	);
	$return['isposter']=$poster['isopen'];	
	$return['orderurl']='jy_pifashop/order.list/';
	set_html('title','会员中心');
	exi($return);
}
if($_RQ['op']=='post'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$post=get_postdata();
	if(!$post['fee']){
		exi('请输入转账金额！','erroe');
	}
	if(!$post['mobile']){
		exi('请输入收款人账户/手机号！','erroe');
	}
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	if($post['password']!=$member['paypassword']){
		exi('支付密码不正确！','erroe');
	}
	if($member['credit2']<$post['fee']){
		exi('转账额度不能大于，当前余额！','erroe');
	}
	$tomember=pdo_get('core_members',array('username'=>$post['mobile']));
	$tomid=$tomember['id'];
	if(!$tomid){
		$tomember=pdo_get('core_members',array('mobile'=>$post['mobile']));
		$tomid=$tomember['onemid']?:$tomember['id'];
	}
	if(!$tomid){
		exi('没找到收款人，转账失败！','erroe');
	}
	model('core/member')->cut_credit2($_SESSION['uid'],$post['fee'],'转账给:'.$post['mobile']);
	model('core/member')->add_credit2($tomid,$post['fee'],$member['username'].'的转账');
	exi('转账成功！');
}
if($_RQ['op']=='password'){
	$post=get_postdata();
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	pdo_update('core_members',array('paypassword'=>$post['password']),array('id'=>$_SESSION['uid']));
	exi('设置成功！');
}